1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.webmacro.servlet;
25
26 import org.webmacro.Broker;
27 import org.webmacro.ResourceException;
28 import org.webmacro.Template;
29 import org.webmacro.engine.StringTemplate;
30
31 /***
32 * This handler gets called if a normal handler could not
33 * be constructed--it writes out an error message
34 * explaining what went wrong.
35 */
36 final class ErrorHandler implements Handler
37 {
38
39 private static final String DEFAULT_ERROR_TEXT =
40 "<HTML><HEAD><TITLE>Error</TITLE></HEAD>\n"
41 + "#set $Response.ContentType = \"text/html\"\n"
42 + "<BODY><H1>Error</H1>"
43 + "<HR>$error</BODY></HTML>";
44
45 private Template _errorTemplate = null;
46
47 /***
48 * The default error handler simply returns its template
49 * @see TemplateStore
50 * @exception HandlerException if you don't want to handle the connect
51 * @return A Template which can be used to interpret the connection
52 */
53 public Template accept (WebContext c)
54 throws HandlerException
55 {
56 Broker broker = c.getBroker();
57 String templateName;
58
59 try
60 {
61 templateName = (String) broker.get("config", WMServlet.ERROR_TEMPLATE);
62 }
63 catch (ResourceException e)
64 {
65 templateName = WMServlet.ERROR_TEMPLATE_DEFAULT;
66 }
67
68 try
69 {
70 _errorTemplate = (Template) broker.get("template", templateName);
71 }
72 catch (ResourceException e)
73 {
74 _errorTemplate = new StringTemplate(broker, DEFAULT_ERROR_TEXT,
75 "WebMacro default error template");
76 }
77
78 return _errorTemplate;
79 }
80
81 /***
82 * Does nothing
83 */
84 public void destroy ()
85 {
86 }
87
88 /***
89 * Does nothing
90 */
91 public void init ()
92 {
93 }
94
95
96 /***
97 * Return the name of this handler
98 */
99 final public String toString ()
100 {
101 return "WebMacro ErrorHandler";
102 }
103 }
104
105